package com.srwl.mytx.activity;

import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.FragmentTransaction;

import com.srwl.easeui.widget.MyTitleBar;
import com.srwl.mytx.R;
import com.srwl.mytx.fragment.PublishTaskRecordFragment;
import com.srwl.mytx.fragment.ReceiveTaskRecordFragment;

public class TaskRecordActivity_v1 extends BaseActivity {


    private MyTitleBar titleBar;
    private PublishTaskRecordFragment publishTaskRecordFragment;
    private ReceiveTaskRecordFragment receiveTaskRecordFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_record_v1);
        titleBar = findViewById(R.id.title_bar);
        // titleBar.setRightTitle("切换");
        showReceiveTaskFragment();
//        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (publishTaskRecordFragment == null || publishTaskRecordFragment.isHidden()) {
//                    showPublishTaskFragment();
//
//                } else {
//                    showReceiveTaskFragment();
//                }
//            }
//        });
    }


    private void showPublishTaskFragment() {
        if (publishTaskRecordFragment == null) {
            publishTaskRecordFragment = PublishTaskRecordFragment.newInstance();
        } else if (!publishTaskRecordFragment.isHidden()) {
            return;
        }
        titleBar.setTitle("任务发布记录");
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        if (receiveTaskRecordFragment != null && !receiveTaskRecordFragment.isHidden()) {
            fragmentTransaction.hide(receiveTaskRecordFragment);
        }

        if (!publishTaskRecordFragment.isAdded()) {
            fragmentTransaction.add(R.id.record_fragment_container, publishTaskRecordFragment);
        }
        fragmentTransaction.show(publishTaskRecordFragment).commit();

    }

    private void showReceiveTaskFragment() {
        if (receiveTaskRecordFragment == null) {
            receiveTaskRecordFragment = ReceiveTaskRecordFragment.newInstance();
        } else if (!receiveTaskRecordFragment.isHidden()) {
            return;
        }
        titleBar.setTitle("任务领取记录");
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        if (publishTaskRecordFragment != null && !publishTaskRecordFragment.isHidden()) {
            fragmentTransaction.hide(publishTaskRecordFragment);
        }
        if (!receiveTaskRecordFragment.isAdded()) {
            fragmentTransaction.add(R.id.record_fragment_container, receiveTaskRecordFragment);
        }

        fragmentTransaction.show(receiveTaskRecordFragment).commit();

    }

}
